package com.ezops.dtcc.model.dao;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;

import com.ezops.dtcc.model.AckNack;

public class AcknowledgementDAO {
	private final static Logger LOGGER = Logger
			.getLogger(AcknowledgementDAO.class);
	private JdbcTemplate jdbcTemplate;

	public AcknowledgementDAO(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	
	public void insert(long dateDiff, AckNack ackNack) {
		String insertSql = "INSERT INTO SDRACKNACK ("
				+ "REPOSITORY, SOURCE, SUBMITTED_FOR_PREFIX, SUBMITTED_FOR_VALUE, DATE_SUBMITTER_PREFIX, "
				+ "PRIMARY_ASSET_CLASS, PRODUCT_ID_PREFIX, PRODUCT_ID_VALUE, MESSAGE_ID, EVENT_ID, "
				+ "USI_PREFIX, USI_VALUE, UTI_PREFIX, UTI, PRIOR_USI_PREFIX, "
				+ "PRIOR_USI_VALUE, PRIOR_UTI_PREFIX, PRIOR_UTI, TRADE_PARTY1_TRANSACTION_ID, TRADE_PARTY2_TRANSACTION_ID, "
				+ "MESSAGE_TYPE, ACTION, TRANSACTION_TYPE, TRADE_PARTY1_ROLE, TRADE_PARTY1_PREFIX, "
				+ "TRADE_PARTY1_VALUE, TRADE_PARTY2_ROLE, TRADE_PARTY2_PREFIX, TRADE_PARTY2_VALUE, EXECUTION_TIMESTAMP, "
				+ "TRADE_DATE, EFFECTIVE_DATE, VERIFICATION_TYPE, CONFIRMATION_DATETIME, CONFIRMATION_TYPE, "
				+ "AS_OF_DATE, VALUATION_DATETIME, MANDATORY_CLEARING_INDICATOR, PARTY1_REPORTING_OBLIGATION, PARTY2_REPORTING_OBLIGATION, "
				+ "REPORTING_JURISDICTION, PARTY1_VOLUNTARY_SUBMISSION, PARTY2_VOLUNTARY_SUBMISSION, ACK_OR_NACK, REASON_CODE, "
				+ "REASON_DESCRIPTION, NET_REPORTING_OBLIGATION, CFTC_EXPECTED, CFTC_ACTUAL, CFTC_DEVIATION, "
				+ "ESMA_EXPECTED, ESMA_ACTUAL, ESMA_DEVIATION, FPML, REPORTING_PURPOSE, INSERT_TIMESTAMP, TIMESTAMP_DIFFERENCE) ";
		insertSql += " VALUES(" 
				+ "?,?,?,?,?,?,?,?,?,?,"
				+ "?,?,?,?,?,?,?,?,?,?," 
				+ "?,?,?,?,?,?,?,?,?,?,"
				+ "?,?,?,?,?,?,?,?,?,?," 
				+ "?,?,?,?,?,?,?,?,?,?,"
				+ "?,?,?,?,?,?,?)";
		
		LOGGER.info("Inserting Record..Message ID ->" + ackNack.getMessageId());
		getJdbcTemplate().update(
				insertSql,
				new Object[] { ackNack.getRespository(), ackNack.getSource(),
						ackNack.getSubmittedForPrefix(),
						ackNack.getSubmittedForValue(),
						ackNack.getDateSubmitterPrefix(),
						ackNack.getPrimaryAssetClass(),
						ackNack.getProductIdPrefix(),
						ackNack.getProductIdValue(), ackNack.getMessageId(),
						ackNack.getEventId(), ackNack.getUsiPrefix(),
						ackNack.getUsiValue(), ackNack.getUtiPrefix(),
						ackNack.getUti(), ackNack.getPriorUsiPrefix(),
						ackNack.getPriorUsiValue(),
						ackNack.getPriorUtiPrefix(), ackNack.getPriorUti(),
						ackNack.getTradeParty1TransactionId(),
						ackNack.getTradeParty2TransactionId(),
						ackNack.getMessageType(), ackNack.getAction(),
						ackNack.getTransactionType(),
						ackNack.getTradeParty1Role(),
						ackNack.getTradeParty1Prefix(),
						ackNack.getTradeParty1Value(),
						ackNack.getTradeParty2Role(),
						ackNack.getTradeParty2Prefix(),
						ackNack.getTradeParty2Value(),
						ackNack.getExecutionTimestamp(),
						ackNack.getTradeDate(), ackNack.getEffectiveDate(),
						ackNack.getVerificationType(),
						ackNack.getConfirmationDateTime(),
						ackNack.getConfirmationType(),
						ackNack.getAsOfDateTime(),
						ackNack.getValuationDateTime(),
						ackNack.getMandatoryClearingIndicator(),
						ackNack.getParty1ReportingObligation(),
						ackNack.getParty2ReportingObligation(),
						ackNack.getReportingJurisdiction(),
						ackNack.getParty1VoluntarySubmission(),
						ackNack.getParty2VoluntarySubmission(),
						ackNack.getAckOrNack(), ackNack.getReasonCode(),
						ackNack.getReasonDescription(),
						ackNack.getNetReportingObligation(),
						ackNack.getCftcExpected(), ackNack.getCftcActual(),
						ackNack.getCftcDeviation(), ackNack.getEsmaExpected(),
						ackNack.getEsmaActual(), ackNack.getEsmaDeviation(),
						ackNack.getFpml(), ackNack.getReportingPurpose(),
						ackNack.getInsertTimestamp(),
						dateDiff});
	}
}
